package com.warm.spring.mvc.filter;


import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/*@Component
@WebFilter(urlPatterns = "/mvc", filterName = "filterB")
@Order(value = 1)*/
public class MyFilterB implements Filter {
    /**
     *  Web浏览器 <==> Web服务器 <==> 过滤器 <==> web资源
     */

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("---过滤器2初始化---");
    }

    @Override
    public void destroy() {
        System.out.println("---过滤器2销毁---");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("---执行过滤器2操作---");
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String requestUri = request.getRequestURI();
        System.out.println("requestUri:" + requestUri);
        //调用该方法后，表示过滤器经过原来的url请求处理方法
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
